package com.base.exp

import android.text.TextUtils
import android.util.Log
import java.util.Calendar

fun Any.log(message: CharSequence?) {
    log("", "" + message)
}

fun Any.log(childTag: String, message: CharSequence?) {
    val tag = this::class.java.name
    val length = tag.length
    var newTag = tag
    if (length >= 20) {
        newTag = tag.substring(length - 20, length)
    }
    if (TextUtils.isEmpty(childTag))
        Log.e(newTag, "$message")
    else {
        Log.e(newTag, "$childTag>>$message")
    }
}

fun logTime(): String {
    val calendar = Calendar.getInstance()
    val hour = calendar.get(Calendar.HOUR_OF_DAY)
    val minute = calendar.get(Calendar.MINUTE)
    val second = calendar.get(Calendar.SECOND)
    val millisecond = calendar.get(Calendar.MILLISECOND)

    return "$hour:$minute:$second.$millisecond"
}